Skip to content

Dataset expansion: +2.2k targeted markdown rows, 9 new detection labels - #12

Merged
bfirestone merged 3 commits into
mainfrom
add-detections-head
Apr 11, 2026
Merged

Dataset expansion: +2.2k targeted markdown rows, 9 new detection labels#12
bfirestone merged 3 commits into
mainfrom
add-detections-head

Conversation

@bfirestone

Copy link
Copy Markdown
Contributor

Summary

This PR closes a critical dataset gap in the training corpus and adds 9 new detection labels for popular embedded languages. Follow-up to the detection label audit work.

The Gap

The prior corpus had zero markdown rows containing rust code blocks and only 9 containing go. The detection head literally cannot learn to detect rust-in-markdown when no such examples exist. Similar gaps existed for swift (6), kotlin (2), lua (2), and objc (3).

The Fix

Adds --content-filter support to pull_real_data to target specific languages when streaming The Stack markdown. Uses this to pull ~2,200 markdown documents containing embedded code blocks for 17 languages.

Coverage improvements (markdown rows containing each language):

Language Before After Δ
rust 0 340
go 9 295 +286
swift 6 173 +167 (new label)
kotlin 2 150 +148 (new label)
lua 2 142 +140 (new label)
r 1 104 +103 (new label)
objc 3 95 +92
graphql 0 82 +82 (new label)
ruby 19 82 +63 (new label)
csharp 42 64 +22 (new label)
powershell 29 37 +8 (new label)
php 17 25 +8 (new label)

New Detection Labels (9)

Added to DETECTION_LABELS with explicit definitions in SYSTEM_PROMPT:

csharp, powershell, ruby, php, swift, kotlin, r, lua, graphql

Each definition includes positive signals (distinctive syntax/keywords) and anti-signals (common confusions with existing labels). The r, swift, and go definitions have a Name alone in prose is not sufficient caveat to prevent prose-mention false positives.

Validation

Ran a 3-model 5k stratified audit after the expansion using gemini-3-flash, sonnet-4.6, and gpt-5.4-mini. Results:

  • rust cross-fires: 3 → 29 (+867%)
  • go cross-fires: 5 → 20 (+300%)
  • All 9 new labels fire with 100% recall on ground-truth markdown rows
  • Inter-annotator agreement ≥0.999 across 3 models for all new labels
  • Zero ruby/rust false positives from the r regex (critical test)

Commits

  1. d33416e — Targeted pull infrastructure: --sub-type, --target, --content-filter, --source-label, --max-skips-multiplier flags + click wrapper + 49 tests including R-regex precision tests
  2. 4cffd46 — 9 new detection labels with SYSTEM_PROMPT definitions and caveats
  3. 7c34e00 — Dataset expansion (2,186 new rows) + audit_detection_labels.py analysis script + DVC hash update

Data

  • golden_train.parquet DVC hash: 3cd90fbd…c15c01ff…
  • Corpus size: 88,440 → 90,626 rows (+2,186 net new)
  • Pushed to DVC remote (B2)
  • Old corpus preserved as golden_train.r4.parquet for rollback

Known Issue (Filed Separately)

Discovered during this work: the existing golden_train.parquet is not a fixed point under the current dedup pipeline — re-running dedup on it alone removes 8,053 rows. Worked around by skipping cross-corpus dedup and using only exact-text deduplication for the expansion. Filed as arc bug textclf-1dd1.013xtr for separate investigation.

Test plan

  • 49 new unit tests for pull infrastructure including R-regex precision (all pass)
  • Dry-run annotation with updated 40-label prompt (verified 40 det columns)
  • 3-model 5k stratified audit on expanded corpus (verified gap closure)
  • Ground-truth recall check (100% on markdown rows containing each language)
  • Feature sanity check on new rows (no NaN/Inf/NULL)
  • Content spot check on 10 random new rows (all legitimate documentation)
  • Internal near-duplicate cleanup (12 pairs removed)
  • DVC push verified (6 files to B2)

Adds --sub-type, --target, --content-filter, --source-label, and
--max-skips-multiplier flags to enable targeted streaming from The Stack
markdown directory. Used to pull language-specific documentation
(markdown documents containing rust/go/etc code blocks) that was
underrepresented in the main corpus.

Also exposes this via `trainr data pull` click command and adds 49 tests
for the new flags, row construction, and content filter regexes.

The content filter regex tests include precision tests for the R
single-letter regex to verify it does NOT false-match on ruby/rust/rs/
rstudio — the R label is particularly fragile because ```r is easy to
confuse with those languages.
Adds csharp, powershell, ruby, php, swift, kotlin, r, lua, graphql to
DETECTION_LABELS. These are popular languages that already appeared in
the corpus as embedded code blocks but could not be detected by the
multi-label head because they had no label.

Updates SYSTEM_PROMPT with explicit definitions for each new label,
covering positive signals (distinctive syntax/keywords) and anti-signals
(common confusions with existing labels like python/ruby, java/kotlin,
swift/objc, and especially r vs ruby/rust/rst).

Adds "Name alone in prose is not sufficient" caveat to r, swift, and go
definitions. These are most susceptible to prose-mention false positives
because the words appear in non-code contexts (descriptions, titles).

Example JSON template updated to include all 40 labels.
… script

Adds ~2,186 markdown documents containing embedded code blocks for 17
languages that were severely underrepresented in the prior corpus.
Target-pull strategy uses content-filter regex on The Stack markdown
stream (e.g. ```rust, ```go, ```swift) to surface documentation with
cross-cutting code examples.

Coverage improvements (markdown rows containing each language):
- rust: 0 → 340  (largest gap; was literally zero)
- go: 9 → 295
- swift: 6 → 173  (new label)
- kotlin: 2 → 150  (new label)
- lua: 2 → 142  (new label)
- r: 1 → 104  (new label)
- python: 42 → 192
- objc: 3 → 95
- ruby: 19 → 82  (new label)
- graphql: ~0 → 82  (new label)
- csharp: 42 → 64  (new label)
- php: 17 → 25  (new label)
- powershell: 29 → 37  (new label)
- (plus incidental boosts to shell/css/ini/dockerfile/sql/html/typescript)

Internal deduplication of 12 near-duplicate pairs (templated Docker Hub
READMEs, LeetCode writeups, cryptocurrency fork READMEs) via FAISS
feature-space L2 threshold 0.1.

Existing corpus preserved exactly — NO cross-corpus dedup was performed
because the existing golden_train.parquet is not a fixed point under the
current dedup pipeline (re-running dedup alone drops 8,053 rows). Filed
as arc bug textclf-1dd1.013xtr for future investigation.

Adds audit_detection_labels.py — new analysis script that quantifies
each detection label's fire rate, cross-fire rate (label != sub_type),
label co-occurrence matrix, per-sub_type distribution, and
inter-annotator agreement across multiple LLM annotators. Used to
validate the dataset expansion via a fresh 5k stratified audit run on
three models (gemini-3-flash, sonnet-4.6, gpt-5.4-mini).

Post-expansion audit results (golden_train v7):
- rust cross-fires: 3 → 29  (+867%)
- go cross-fires:   5 → 20  (+300%)
- All 9 new labels fire with 100% recall on ground-truth markdown rows
- Inter-annotator agreement ≥0.999 for new labels across 3 models
- Zero ruby/rust false positives from r regex (critical test)

Data tracked via DVC. golden_train.parquet md5 updated from
3cd90fbd60ec30e85fb0a50c29151ac8.dir to c15c01ff8546992d023059923ccb7b30.dir.
Old corpus preserved as golden_train.r4.parquet for rollback.
@bfirestone
bfirestone merged commit c360b84 into main Apr 11, 2026
1 check passed
@bfirestone
bfirestone deleted the add-detections-head branch April 11, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant